<template>
    <div class="">
        <tree-node v-for="(item, index) in cloneData" :key="index" :data="item" :show-checkbox="showCheckbox"></tree-node>
    </div>
</template>

<script type="text/javascript">
import TreeNode from './i-tree-node.vue';
import { deepCopy } from '@/utils/assist';


export default {
    name: 'tree',
    components: {
        TreeNode
    },
    props: {
        data: {
            type: Array,
            default(){
                return []
            }
        },
        showCheckbox: {
            type: Boolean,
            default: false,
        }
    },
    data(){
        return {
            cloneData: []
        }
    },
    created(){
        this.rebuildData();
    },
    watch: {
        data(){
            this.rebuildData()
        }
    },
    methods: {
        rebuildData(){
            this.cloneData = deepCopy(this.data);
        },
        emitEvent(eventName, data){
            this.$emit(eventName, data, this.cloneData)
        }
    }
};
</script>

<style lang="less" scoped></style>
